#include "CommentRecord.h"

#include <QDebug>

CommentRecord::CommentRecord()
{

}

QString CommentRecord::buildRecord() const
{
    QString record = recordTypeSymbol(RecordType::Comment);
    record += FIELD;
    record += QString::number(frameIndex);
    record += FIELD;
    record += sourceList.value(source);
    record += FIELD;
    record += message;
    record += FIELD;
    record += commentList.value(commentType);
    record += CR;

    return record;
}

bool CommentRecord::analyzeRecord(const QString &str)
{
    QStringList fields = str.split(FIELD);

    if(fields.count() < 5 || fields.value(0) != recordTypeSymbol(RecordType::Comment)) {
        // qWarning() << "CommentRecord: Syntax Error!";
        return false;
    }

    if(sourceList.indexOf(fields[2]) >= 0) {
        source = static_cast<Source>(sourceList.indexOf(fields[2]));
    }

    message = fields[3];
    if(commentList.indexOf(fields[4]) >= 0) {
        commentType = static_cast<CommentType>(commentList.indexOf(fields[4]));
    }

    return true;
}
